package net.sx.minemodule.mvp.activities;

import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.dialog.ECAlertDialog;

import net.sx.minemodule.MineApiUtils;
import net.sx.minemodule.R;
import net.sx.minemodule.databinding.MineActivityResearcherBinding;
import net.sx.minemodule.mvp.presenters.MineResearcherPresenter;
import net.sx.minemodule.mvp.views.MineResearcherView;

/**
 * add shibo.zheng
 * 19/06/13
 * 我是调研员
 */
@Route(path = ARouterPath.PATH_MINE_RESEARCHER)
public class MineResearcherActivity extends MyBaseFragmentActivity<MineActivityResearcherBinding, MineResearcherPresenter> implements MineResearcherView {
    private String commissionType;  //提现
    private String companyName; //公司名称

    @Override
    protected int getLayout() {
        return R.layout.mine_activity_researcher;
    }

    @Override
    protected void initEvent() {
        //调用获取个人提成信息界面数据接口
        MineApiUtils.getCommissionInfo(infoModel -> {
            if (infoModel != null) {
                mBinding.lastCommission.setText(infoModel.getLastMonth());  //上月提成数据设置
                mBinding.thisCommission.setText(infoModel.getThisMonth());  //本月提成数据设置
                mBinding.spreadNum.setText(infoModel.getExtensionNumber()); //推广人数数据设置
            }
        }, throwable -> Log.d(TAG, "accept: throwable == " + throwable.toString()));
    }

    @Override
    protected MineResearcherPresenter getPresenter() {
        return new MineResearcherPresenter(this);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        setTitle("我是调研员");
        companyName = "上海领域科技有限公司"; //公司名（此处后续需要添加动态公司名）
        //本月已有产值
        mBinding.mineAssetsThismonth.setLeftTextAndRightTextRightImg("本月已有资产（元）", "30000", false);
        mBinding.mineAssetsThismonth.setRightTextColor(R.color.color_ea3333);
        //上月产值
        mBinding.mineAssetsLastmonth.setLeftTextAndRightTextRightImg("上月产值（元）", "40000", false);
        mBinding.mineAssetsLastmonth.setRightTextColor(R.color.color_ea3333);
        //合作公司
        mBinding.minePartnerCompany.setLeftTextAndRightTextRightImg("合作公司", companyName, true);
        mBinding.minePartnerCompany.setRightTextColor(R.color.color_bbbbbb);
        mBinding.minePartnerCompany.setOnClickListener(v -> ARouter.getInstance().build(ARouterPath.PATH_COMPANY_INFO).withString("companyName", companyName).navigation());
        //常见问题
        mBinding.mineCommonProblem.setOnClickListener(v -> ARouter.getInstance().build(ARouterPath.PATH_COMMON_PROBLEM).navigation());
        //调研员须知
        mBinding.mineResearcherNotice.setOnClickListener(v -> {
            //弹出框
            ECAlertDialog dialog = ECAlertDialog.buildAlert(MineResearcherActivity.this,
                    R.string.mine_researcher_notice,
                    R.string.picture_cancel,
                    (dialog1, which) -> dialog1.dismiss());
            dialog.setContentPadding(10, 20,10,20);
            dialog.setTitle("");
            dialog.setMesGravity(Gravity.LEFT);
            dialog.show();
        });
        //提成明细
        mBinding.mineCommissionInfo.setOnClickListener(v -> {
            commissionType = "CommissionList";
            ARouter.getInstance().build(ARouterPath.PATH_RECORD_INFO).withString("recordInfoType", commissionType).navigation();
        });


    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTopRightButton("历史提成明细", 0, v -> {
            commissionType = "HistoryCommission";
            ARouter.getInstance().build(ARouterPath.PATH_RECORD_INFO).withString("recordInfoType", commissionType).navigation();
        });
    }
}
